<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="css/element.css" rel="stylesheet"/>
    <link href="css/styleindex.css" rel="stylesheet"/>
    <link href="./css/swiper.min.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background: #ffffff;">

  <div class="mui-content" style="margin-top:30px;">
    <div id="vm" class="x-examok" v-cloak>
        <!--  -->
        <div class="x-train-tabs swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide x-train-items" v-for="(item,index) in tabsdata" :key="item.id" @click="changetab(index,item.id)" :class="{active:curId==index}">{{item.title}}</div>
            </div>
        </div>
        <!--  -->
        <div class="x-ico-month x-ico-month2">
            <el-date-picker v-model="cardsmonth" :type="timetype.type" placeholder="选择日" @change="getmonth" :format="timetype.format" :value-format="timetype.valueformat" :editable="notkey"></el-date-picker>
        </div>
        <!--  -->
        <el-table :data="tabledata">
            <el-table-column label="任务名称" width="130" fixed>
                <template slot-scope="scope">
                {{scope.row.title}}
                </template>
            </el-table-column>
            <el-table-column label="任务来源" width="130">
                <template slot-scope="scope">
                {{scope.row.source_title}}
                </template>
            </el-table-column>
            <el-table-column label="完成确认" width="130">
                <template slot-scope="scope">
                <el-button type="primary" v-if="scope.row.is_finish=='0'" @click="examok(scope.row.id,scope.row.title)" size="mini">点击确认</el-button>
                <div v-else>
                    <div v-if="scope.row.is_finish==1">已完成</div>
                    <div v-if="scope.row.is_finish==2">未完成</div>
                </div>
                </template>
            </el-table-column>
            <el-table-column label="自我评价" width="130">
                <template slot-scope="scope">
                    <el-button type="primary" v-if="scope.row.my_score=='0'" @click="getnumber(scope.row.id,scope.row.title,'1')" size="mini">点击评价</el-button>
                    <el-button type="text" disabled  v-else size="mini">{{scope.row.my_score}}分</el-button>
                </template>
            </el-table-column>
            <el-table-column label="上级评价" width="">
                <template slot-scope="scope">
                {{scope.row.leader_score}}分
                </template>
            </el-table-column>
            <el-table-column label="查看内容" width="" v-if="isshowpro">
                <template slot-scope="scope">
                <el-button type="text" @click="editfavo(scope.row.title,scope.row.describe)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="x-task-rate">
            <div class="x-task-t">执行力指数：</div>
            <el-rate v-model="taskratevalue" disabled show-score text-color="#058142" :colors="ratecolor" :max="10" :allow-half="ishalf"></el-rate>
        </div>
        <!--  -->
      <el-dialog :title="'请对“'+scoretoasttitle + '”进行打分'" :visible.sync="dialogVisible" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="x-tra-nin">
          <el-input-number v-model="scoredata" @change="getscorenum" :min="1" :max="10" label="描述文字"></el-input-number>
          <div class="x-tra-desc"></div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="okgetscore">确 定</el-button>
        </span>
      </el-dialog>
      <!--  -->
      <el-dialog :title="toasttitle" :visible.sync="edittoast" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <span>{{toastcon}}</span>
      </el-dialog>
    </div>
  </div>

  <script type="text/javascript" src="./script/vue.js"></script>
  <script type="text/javascript" src="./script/element.js"></script>
  <script type="text/javascript" src="./script/api.js"></script>
  <script type="text/javascript" src="./script/base.js"></script>
  <script type="text/javascript" src="./script/swiper.min.js"></script>
	<script>
apiready = function () {



    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabsdata:[
              {title:'工作站任务',id:0},
              {title:'管理任务',id:1},
              {title:'评价任务',id:2},
              {title:'委派任务',id:3},
              {title:'学习任务',id:4},
              {title:'训练任务',id:5},
              {title:'自定义任务',id:6}
          ],
          curId:0,
          timetype:{
              type:'date',
              format:'yyyy 年 MM 月dd 日',
              valueformat:'yyyyMMdd'
          },
          cardsmonth:'',
          notkey:false,
          tabledata:[],
          ratecolor:['#058142','#058142','#058142','#058142','#058142'],
          ishalf:true,
          taskratevalue:0,
          isshowpro:true,
          dialogVisible:false,
          scoretoasttitle:'',
          scoredata:0,
          edittoast:false,
          toasttitle:'',

        }
      },
      created:function() {
        var that=this;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate();
        if(month<10){
          month = '' + 0 + month;
        }
        if(day<10){
          day = '' + 0 + day;
        }
        var toMonth = '' + year + month + day;
        that.cardsmonth = toMonth;
        this.gettrainadmin()
        that.$nextTick(function(){
            var mySwiper = new Swiper('.swiper-container',{
                freeMode: true,
                loop:false,//设置 active slide 居中后，会有左右留白现象，添加此会让未尾的导航补齐前后空白
                slideToClickedSlide: true,//设置为true则点击slide会过渡到这个slide。
                slidesPerView: 3.5,
                centeredSlides: false,//设定为true时，active slide会居中，而不是默认状态下的居左。
                spaceBetween: 10,//slide之间设置距离
                slidesOffsetBefore: 0,//设定slide与左边框的预设偏移量
                slidesOffsetAfter: 0,//设定slide与右边框的预设偏移量

            });

        });

      },
      mounted:function(){
        var that=this;

      },
      methods: {
          //查看内容
        editfavo:function(title,content){
          var that = this;
          that.toasttitle = title;
          that.toastcon = content;
          that.edittoast = true;
        },
          //自我评价
        getnumber:function(id,name,type){
          var that = this;
          that.dialogVisible = true;//显示弹窗
          that.scoretoasttitle = name;
          that.scoretoastid = id;

        },
        //获取打分分数
        getscorenum:function(val){
          var that = this;
          that.scoredata = val;
        },
        //自我评价提交
        okgetscore:function(){
          let that=this;
          that.dialogVisible = false;//显示弹窗
          api.ajax({
            url:baseurl+'api/task/setMyScore',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.scoretoastid,
                score:that.scoredata
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.gettrainadmin()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
          //完成考核确认
        examok:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”是否完成',
              cancelTitle: '取消',
              buttons: ['已完成', '未完成']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              console.log(index);// 1 2
              if(index=='1'){
                that.examgoajax(id,index)
              }else if(index=='2'){
                that.examgoajax(id,index)
              }

          });

        },
        //完成确认 提交
        examgoajax:function(id,index){
          let that=this;
          api.ajax({
            url:baseurl+'api/task/setFinish',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id,
                type:index
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.gettrainadmin()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        changetab(index,id){
            var that = this;
            that.curId = index;
            if(index===3 || index===6){
                this.timetype = {
                    type:'month',
                    format:'yyyy 年 MM 月',
                    valueformat:'yyyyMM'
                }
            }else{
                this.timetype = {
                    type:'date',
                    format:'yyyy 年 MM 月dd 日',
                    valueformat:'yyyyMMdd'
                }
            }
            if(index===2 || index===3){//评价任务不显示查看内容
                this.isshowpro = false
            }else{
                this.isshowpro = true
            }

        },
        getmonth:function(){

        },
        //列表0
        gettrainadmin:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/task/ws',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.cardsmonth,
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              that.tabledata = ret.data.list;//0未操作 1完成 2未完成 
              that.taskratevalue = ret.data.implement;
              
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
